package com.yiyang.controller;


import com.yiyang.pojo.Building;
import com.yiyang.pojo.Result;
import com.yiyang.service.BuildingService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/building")
public class BuildingController {
    @Resource
    private BuildingService buildingService;

    @GetMapping("/list")
    public Result<List<Building>> getBuilding(
            @RequestParam(name = "currentPage" ,defaultValue = "1",required = false) Integer currentPage,
            @RequestParam(name = "pageSize" ,defaultValue = "10",required = false)Integer pageSize,
            @RequestParam(name = "name",defaultValue = "",required = false)String name,
            @RequestParam(name = "height",defaultValue = "",required = false)String  height) {
            return this.buildingService.getBuilding(currentPage,pageSize,name,height);
    }

    @PostMapping("/add")
    public Result<Void> addBuilding(@RequestBody Building building){
        return this.buildingService.addBuilding(building);
    }

    @PutMapping("/update")
    public Result<Void> updateBuilding(@RequestBody Building building) {
        return this.buildingService.updateBuilding(building);
    }

    @DeleteMapping("/delete")
    public Result<Void> deleteBuildingById(@RequestParam(name = "id",required = true)String id){
        return this.buildingService.deleteBuildingById(id);
    }
}
